package com.flong.juc.charter1;

/**
 * @Author:liangjl
 * @Date: 2020/7/4-21:02
 * @Eamil:jilongliang@sina.com
 * @Description:
 */
public class MyTest6 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new MyTest6Thread();
        thread.start();
        thread.interrupt();
    }
}

class MyTest6Thread extends Thread {
    @Override
    public void run() {
        try {
            for (int i = 0; i < 10000; i++) {
                if (this.isInterrupted()) {
                    System.out.println("已经停止打断一半，我要退出");
                    //break;
                    //结束线程代码
                    throw new InterruptedException();
                }
                System.out.println("i=" + i);
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }

        System.out.println("end for ");
    }
}

